package com.usoft.thrift.example;

import org.apache.thrift.TException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.TimeUnit;

/**
 * Created by xinxingegeya on 16/3/2.
 */
public class GreetClient {

    public static void main(String args[]) {

        long startTime = System.nanoTime();

        long endTime = startTime + TimeUnit.MILLISECONDS.toNanos(5000);

        ApplicationContext context = new ClassPathXmlApplicationContext("spring-client.xml");
        GreetServiceRpc.Iface greetService = (GreetServiceRpc.Iface) context.getBean("greetService");

        long now;
        long count = 0;
        try {
            do {
                String resp = greetService.greet("hello world");
                now = System.nanoTime();
                count++;
            } while (endTime > now);
            System.out.println("request count:" + count);
        } catch (TException e) {
            e.printStackTrace();
        }
    }
}
